package com.exam.demo.controller.leave;



import com.exam.demo.domain.Business;
import com.exam.demo.service.assist.AssistService;
import com.exam.demo.service.business.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/business")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @Autowired
    private AssistService assistService;

    @ResponseBody
    @PostMapping(value = "/list")
    public  Object getList(Business business){
        HashMap<String,Object> map = new HashMap<>();
        List<Business> list = businessService.getList(business);
        map.put("list",list);
        return  map;
    }



    @ResponseBody
    @PostMapping(value = "/add")
    public  Object add(@RequestBody @Validated() Business business){
        HashMap<String,Object> map = new HashMap<>();
        Boolean success = businessService.add(business) > 0;
        map.put("result",success ? "yes" :"no");
        return  map;
    }


    @ResponseBody
    @PostMapping(value = "/audit")
    public  Object audit(Business business){
        HashMap<String,Object> map = new HashMap<>();
        Boolean success = businessService.audit(business) >0;
        map.put("result",success ? "yes" :"no");
        return  map;
    }


    @ResponseBody
    @GetMapping(value = "/getChart")
    public  Object getChart(){
        HashMap<String,Object> map = new HashMap<>();
        List<Map<String,Object>> list = businessService.getChart();
        map.put("list",list);
        return  map;
    }



}
